package adke.gui.animations;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class TextAnimation extends Animation
{
    private int framesShown, x, y;
    
    private int lastX, lastY;
    
    // showtime is het aantal frames dat we de tekst laten zien
    public TextAnimation(String text, int x, int y)
    {
        super();
        
        int framesShown = 0;
        this.x = x;
        this.y = y;
        
        lastX = -1;
        lastY = -1;
    }

    // geef aan of de animatie al is afgelopen
    public boolean isDone()
    {
        return framesShown >= duration;
    }

    // teken het volgende frame
    public Rectangle nextFrame(Graphics2D g2d)
    {
        if (isDone()) return new Rectangle(lastX, lastY, 10, 10);
        
        // OUD
        
        if (lastX != -1 && lastY != -1)
        {
            paintTransparant(g2d);
            g2d.fillRect(lastX, lastY, 10, 10);
        }
        
        // NIEUW
        paintNormal(g2d);
        
        g2d.setColor(Color.WHITE);
        
        lastX = x + (framesShown*3);
        lastY = y;
        
        g2d.fillRect(lastX, lastY, 10, 10);
                
        framesShown++;
        
        // geef aan welk gedeelte veranderd is
        return new Rectangle(lastX, lastY, 10, 10);
    }

}
